package com.retch.wenchengmao.sqlitedeme2;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

/**
 * author:wenchengmao
 * time:  2017/3/20.
 * email: wenchengmao@yeah.net
 */

public class AddContentActivity extends Activity {
    int id;
    String name;
    double tuition;
    float price;
    private EditText info_id,names,tuitions,prices;
    private Button addData;
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_content);
        initView();
        click();
    }

    public void initView(){
        info_id=(EditText)findViewById(R.id.info_ids);
        names=(EditText)findViewById(R.id.names);
        tuitions=(EditText)findViewById(R.id.tuitions);
        prices=(EditText)findViewById(R.id.prices);
        addData=(Button) findViewById(R.id.add_data);
    }


    public void click()
    {
        addData.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                id = Integer.parseInt(info_id.getText().toString());
                name = names.getText().toString().trim();
                tuition = Double.parseDouble(tuitions.getText().toString());
                price = Float.parseFloat(prices.getText().toString());
                Student student = new Student(id, name,tuition,price);
                MySQLiteHelper mySQLiteHelper= new MySQLiteHelper(AddContentActivity.this, "db_test5", null, 1);
                mySQLiteHelper.insertSingleDate(student);
                Toast.makeText(AddContentActivity.this, "增加数据成功!", Toast.LENGTH_LONG).show();
                finish();
            }
        });

    }

}
